package com.案例.集合中元素写到文件;

import lombok.SneakyThrows;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.ArrayList;

public class Demo {
    @SneakyThrows
    public static void main(String[] args) {
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("hello");
        arrayList.add("world");
        arrayList.add("java");

        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("java.txt"));

        for (String s : arrayList) {
            bufferedWriter.write(s);
            bufferedWriter.newLine();
            bufferedWriter.flush();
        }

        bufferedWriter.close();
    }
}
